package com.aiwiown.snackmq.console.web;

import com.aiwiown.snackmq.common.dto.TopicInfo;
import com.aiwiown.snackmq.console.service.SnackMQAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api")
public class TopicApiController {

    @Autowired
    private SnackMQAdminService adminService;
    @GetMapping("/topics")
    public ResponseEntity<?> listTopics() {
        try {
            List<TopicInfo> topics = adminService.listTopics();
            return ResponseEntity.ok(topics);
        } catch (Exception e) {
            log.warn("Failed to fetch topic list for API: {}", e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to fetch topics: " + e.getMessage());
        }
    }
}